import moment from 'moment'
const isNum9=n=>n<10?`0${n}s后重新发送`:`${n}s` //倒计时60s
//倒计时
export const send600=opt=>{

  if(opt.count>-1){
    opt.timer = setInterval(()=>{
      opt.count -=1
      opt.codeText =`${isNum9(opt.count)}`
      opt.isSend = true
      if(opt.count<=0){
        opt.count = 60
        opt.codeText = '获取验证码'
        opt.isSend = false
        clearInterval(opt.timer)
      }
    },1000)
  }
}
/**
 * @param { string } value
 * 验证手机号中国(严谨), 根据工信部2019年最新公布的手机号段

 */
export const isMPStrict = value => /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1|8|9]))\d{8}$/g.test(value)

//计算时间属性
export const getCalcTimer= timer=> {
  if(timer === 0 || typeof timer !== 'number') {
    return '00:00'
  }
  let mm = Math.floor(timer / 60)
  let ss = Math.floor(timer % 60)
  if(mm < 10) {
    mm = '0' + mm
  }
  if(ss < 10) {
    ss = '0' + ss
  }
  return mm + ':' + ss
}
//时间选择
export const selectTimeData={
  show:false,
  id:'',//对应公司id
  value:'',//对应公司值
  list:[],//数据
  index:[],//在那一项
  endTime: '', //结束时间
  startTime: '', //开始时间
  appointmentDate: '', //预约日期
  timeParams:{
    year: true,
    month: true,
    day: true,
    hour: true,
    minute: true,
    second: true,
    // 选择时间的时间戳
    timestamp: true,
  },//时间方式
}
//初始化时间
export function getTimeDate() {
  const time = moment()
  const y = time.format('YYYY')
  const m = time.format('MM')
  const d = time.format('DD')
  const M = time.format('HH')
  const H = time.format('mm')
  const startTime = time.subtract(0, 'y').format('YYYY')
  const endTime = time.add(15, 'y').format('YYYY')
  return {
    yms:`${y}-${m}-${d} ${M}:${H}`,
    startTime,endTime
  }
}


export const selectPicData={
  show:false,
  id:'',//对应公司id
  list:[],//数据
  index:[],//在那一项
}
